<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>节点对象</title>
    <style>
        div {
            border: 3px solid red;
        }

        #div1 {
            width: 200px;
            height: 200px;
        }

        #div2 {
            width: 100px;
            height: 100px;
        }

        #div3 {
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<div id="div1">
    <div id="div2">div2</div>
    div1
</div>
<a href="javascript:void (0)" id="del">删除子节点</a>
<a href="javascript:void (0)" id="add">添加子节点</a>


</body>
</html>

<script>
    /*
    以链接的方式添加或者删除子节点
    * 元素节点
    * 属性节点
    * 文本节点
    */
    //删除子节点
    var Element_del = document.getElementById("del");
    Element_del.ondblclick = function () {
        var div1 = document.getElementById("div1");
        var div2 = document.getElementById("div2");
        div1.removeChild(div2);
    }
    //添加子节点
    var add = document.getElementById("add");
    add.onclick = function () {
        var div1 = document.getElementById("div1");
        var div3 = document.createElement("div");
        div3.setAttribute("id", "div3")
        div1.appendChild(div3)
    }
</script>